from PyQt6.QtGui import QIcon
from PyQt6.QtWidgets import QWidget, QPushButton, QApplication
import sys
from PyQt6 import uic
import platform

from MessageBox.SystemMismatchMessageBox import SystemMismatchMessageBox
from Pages.OperateWindow import OperateWindow

from Utils.CommonUtils import selectDisk


class Main:

    def __init__(self):
        self.disk_virtual_path = None  # 磁盘真实地址
        self.operateWindow = None  # 操作页面
        self.ui: QWidget = uic.loadUi("./UI/test.ui")
        self.ui.setWindowIcon(QIcon("FormatRecovery.ico"))
        self.ui.show()

        self.init_buttons()

    def init_buttons(self):
        # Windows 按钮绑定事件
        windows_button: QPushButton = self.ui.findChild(QPushButton, "windows_button")
        windows_button.clicked.connect(lambda: self.confirmSystem(windows_button.text()))

        # Unix 按钮绑定事件
        unix_button: QPushButton = self.ui.findChild(QPushButton, "unix_button")
        unix_button.clicked.connect(lambda: self.confirmSystem(unix_button.text()))

    def confirmSystem(self, arg: str):
        # 获取系统名
        system_name = platform.system()
        # 判断点击的按钮是否为该系统
        if system_name in arg:
            disks = selectDisk()
            self.operateWindow = self.operateWindowCreate(disks)
        else:
            SystemMismatchMessageBox().show()

    def operateWindowCreate(self, disks: list):
        self.ui.close()
        return OperateWindow(self, disks)


if __name__ == '__main__':
    app = QApplication(sys.argv)

    main = Main()

    sys.exit(app.exec())
